package dd.prog2.exercises.set11.a1;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class simpleCounter implements ActionListener{

	public static void main(String[] args) {
		new simpleCounter().start();
	}

	JTextField textfield;
	public void start() {
		JFrame frame = new JFrame("A1 simple counter");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(null);
		frame.setLocation(250, 250);
		frame.setResizable(false);
		frame.setSize(200, 180);

		Font f = new Font("SansSerif", Font.BOLD, 80);
		textfield = new JTextField("0");
		textfield.setLocation(0, 0);
		textfield.setSize(200,120);
		textfield.setHorizontalAlignment(JTextField.CENTER);
		textfield.setFont(f);
		
		JButton count = new JButton("Count");
		count.setLocation(0, 121);
		count.setSize(200, 30);
		count.addActionListener(this);
//		count.addActionListener(new ActionListener(){
//			public void actionPerformed(ActionEvent ae) {
//				String text = textfield.getText();
//				int z = Integer.parseInt(text);
//				textfield.setText((++z)+"");
//			}
//		});
		
		frame.getContentPane().add(textfield);
		frame.getContentPane().add(count);
	
		frame.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent ae) {
		String text = textfield.getText();
		int z = Integer.parseInt(text);
		textfield.setText((++z)+"");
	}
}
